﻿function AsCheckBoxCombo_StopPropagation(e) {
    //cancel bubbling
    e.cancelBubble = true;
    if (e.stopPropagation) {
        e.stopPropagation();
    }
}
function AsCheckBoxCombo_ItemCheckBoxClick(sender, cboClientID) {
    var combo = $find(cboClientID);
    AsCheckBoxCombo_SetText(combo);
}
function AsCheckBoxCombo_OnClientLoad(sender, agrs) {
    AsCheckBoxCombo_SetText(sender);
    document.getElementById(sender.get_id() + "_DropDown").onclick = function(e) {
        AsCheckBoxCombo_SetText(sender);
    };
    document.getElementById(sender.get_id() + "_Input").onkeyup = function() {
        AsCheckBoxCombo_SetText(sender);
    }

}
function AsCheckBoxCombo_SetText(combo) {
    //holds the values of all checked items
    var selectedText = "";
    //get the collection of all items
    var items = combo.get_items();
    //enumerate all items
    for (var i = 0; i < items.get_count(); i++) {
        var item = items.getItem(i);
        //get the checkbox element of the current item
        var uxCheckbox = $get(combo.get_id() + "_i" + i + "_uxItemCheckBox");
        if (uxCheckbox != null && uxCheckbox.checked) {
            if (selectedText != "") selectedText += ", ";
            selectedText += item.get_text();
        }
    }
    combo.set_text(selectedText);
}
function AsCheckBoxCombo_getSelectedValues(comboClientID) {
    var combo = $find(comboClientID);
    //holds the values of all checked items
    var selectedValues = "";
    //get the collection of all items
    var items = combo.get_items();
    //enumerate all items
    for (var i = 0; i < items.get_count(); i++) {
        var item = items.getItem(i);
        //get the checkbox element of the current item
        var uxCheckbox = $get(combo.get_id() + "_i" + i + "_uxItemCheckBox");
        if (uxCheckbox != null && uxCheckbox.checked) {
            if (selectedValues != "") selectedValues += "$";
            selectedValues += item.get_value();
        }
    }
    return selectedValues;
}
function AsCheckBoxCombo_FooterCheckBoxClick(comboClientID, checkAll) {
    var combo = $find(comboClientID);
    //get the collection of all items
    var selectedText = "";
    var items = combo.get_items();
    //enumerate all items
    for (var i = 0; i < items.get_count(); i++) {
        var item = items.getItem(i);
        //get the checkbox element of the current item
        var uxCheckbox = $get(combo.get_id() + "_i" + i + "_uxItemCheckBox");
        if (uxCheckbox != null) {
            uxCheckbox.checked = checkAll;
        }
        if (checkAll) {
            if (selectedText != "") selectedText += ", ";           
            selectedText += item.get_text();
        }
    }
    combo.set_text(selectedText);
    return false;
}